nesmakerfandomcom-20200214-history
Introduction to NESmaker Scripting
If you have worked through the NES Maker video tutorials, and made a few simple game projects, you may be getting to the point where you feel limited by NES Maker's built-in scripts. Learning to modify NES Maker's existing scripts and create your own can open up the possibilities of what you can do exponentially. I am going to tell you that you can learn to do this. You don't need to be good at math, and you don't need to be a programmer (Though those will certainly make things easier). You don't even need to know what language NES Maker's code is in. You will be learning this in the upcoming articles. You can start from zero, and learn all you need to know to make a unique game. Quick Math Lesson: Number Systems You should be somewhat familiar with the number systems that NES Maker uses. Decimal Number System This is the number system we are all familiar with. 0 1 2 3 4 5 6 7 8 9 10 and so on. In some cases you may not be able to directly represent these numbers using code, and will have to convert a number between the number systems. Luckily, you don't have to learn how to do this, as NES Maker has a conversion tool built directly into the interface.You can find it in your plugins folder to the left. Binary Number System You have probably heard of this, even if you are not familiar with how it works. Binary is made up of just two numbers: 0 and 1 You can represent Decimal numbers using a combination of these. In NES Maker, you usually find them in sequences that are either 8 or 16 digits long. (one digit in this number system is called a bit, 8 is called a byte) Here is an example of how to read it, and you can make any number by following this pattern: 0 00000000 1 00000001 2 00000010 3 00000011 4 00000100 5 00000101 6 00000110 7 00000111 (to increase by 1, look at the rightmost number. If it is zero change it to 1. If it is 1 change it to zero and look one digit to the left, repeat with this digit.) You do not need to be able to do binary math in your head to program NES Maker. It is just useful to be able to understand what you are looking at. Hexadecimal Number System Called Hexadecimal because each digit can be a value 1-16. At this point it is good to mention that when you are counting with programming: ALWAYS -ALWAYS- start counting at zero. This is how it happens in memory, and it will save you a lot of headaches later on. Its a weird concept to wrap your head around, but you use letters of the alphabet like so: 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 A 11 B 12 C 13 D 14 E 15 F This is how numbers will most often be represented in assembly programming. Programming Language: ASM6502 NES Maker's script code is written in ASM6502, the same language that was originally used to program NES games. It is a form of assembly language, an early programming language that gives access directly to the NES systems hardware and memory. This language gives you a set of commands called Operation Codes which allow you to manipulate memory locations called registers in the NES hardware. This may sound complicated, but it is actually a fairly simple concept. For example: LDA temp Will load the value currently in temp, and allow you to manipulate it. STA temp Will store the value you are currently working with in temp. CMP temp Will compare the value you currently have loaded with the value in temp, allowing you to react according to if the value was less than, greater than, or equal to. Don't worry about memorizing them for now. We will look at individual Operation Codes in more detail in a later article. Getting ready to make changes to scripts Before you touch any code, you should set things up to make your life easier. First of all, you should never -ever- save over any of the default NESMaker scripts. Any edits you make should be to a new copy of the script. To make this easier if you plan to make a lot of edits to your scripts, I recommend starting your game off with a brand new module. You can create a copy of the entire script folder that it is safe to work on without breaking any existing scripts. To learn how to create your own module, I recommend checking here: Make your own Nesmaker Module. Another thing you may want to do is get yourself a more advanced code editor. Nesmaker has a built-in code editor that works fine for small edits, but if you are going to make large changes or write entire scripts from scratch I recommend a dedicated code editor like Notepad++ This will make it much easier to keep your code organised, and result in less accidental losses. (Nesmaker still has crashes every once and a while) It also has added features such as dark themes for reduced eye strain and multiple tabs so you can open and compare multiple different scripts at once.